package com.magic.interview.模拟.LC1763最长的美好子字符串;

import java.util.HashSet;
import java.util.Set;

/**
 * @author laoma
 * @create 2022-02-01 9:37
 */
public class Solution2 {
    public String longestNiceSubstring(String s) {
        int n = s.length();
        String ans = "";
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if(ans.length() < j - i + 1 && check(s.substring(i,j+1))){
                    ans = s.substring(i , j + 1);
                }
            }
        }
        return ans;
    }

    private boolean check(String s) {
        Set<Character> set = new HashSet<>();
        char[] chs = s.toCharArray();
        for (char ch : chs) {
            set.add(ch);
        }
        for (char ch : chs) {
            char a = Character.toLowerCase(ch);
            char b = Character.toUpperCase(ch);
            if(!set.contains(a) || !set.contains(b)){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int lower= 0;
        char ch = 'b';
        lower |= 1 << (ch - 'a');
        System.out.println(lower);
        var a = 5;
        a|=3;
        System.out.println(a);
    }
}
